import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:kepu/page/plant_detail_page/provider/plant_detail_provider.dart';
import 'package:kepu/widgets/error_widget.dart';
import 'package:kepu/widgets/loading_widget.dart';
import '../../widgets/custom_detail_widget.dart';

class PlantDetailPage extends ConsumerWidget {
  const PlantDetailPage(this.id, {super.key});

  final int id;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var plantDetailResult = ref.watch(plantDetailProviderProvider(id));
    var size = MediaQuery.of(context).size;
    return Scaffold(
      body: plantDetailResult.when(
        data:
            (value) => customDetailWidget(
              size: size,
              context: context,
              imageUrl: value.image,
              name: value.name,
              description: value.description,
              type: value.type,
              location: value.region,
            ),
        error: (e, st) => errorWidget(),
        loading: () => loadWidget(context),
      ),
    );
  }
}
